package br.ufc.minijavaufc.semantic;

public class Table {

	String identifier;
	int value;
	Table tail;
	
	public Table(String identifier, int value, Table tail) {
		super();
		this.identifier = identifier;
		this.value = value;
		this.tail = tail;
	}
	
	public Table update(String identifier, int value) {
		Table table = new Table(identifier, value, this);
		table.tail = this;
		return table;
	}
	
	public int lookup(String key) {
		int resultado = -1;
		Table table = this;
		while(table.identifier != null && !table.identifier.equals(key)) {
			table = table.tail;
		}
		if(table.identifier == key) {
			resultado = table.value;
		}
		return resultado;
	}
	
}
